package com.whz.workmanageol.utils;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 校验电子邮箱 电话等的合法性
 */
public class VerifyUtils {
    private static final Logger logger = LoggerFactory.getLogger(VerifyUtils.class);
    private static final String CHECK_EMAIL = "\\w+@\\w+(\\.\\w{2,3})*\\.\\w{2,3}";
    private static final String CHECK_TEL = "0\\d{2,3}[-]?\\d{7,8}|0\\d{2,3}\\s?\\d{7,8}|13[0-9]\\d{8}|15[1089]\\d{8}";

    public static boolean isLegalEmail(String dest){
        return isLegal(CHECK_EMAIL, dest);
    }

    public static boolean isLegalTel(String dest){
        return isLegal(CHECK_TEL, dest);
    }
    private static boolean isLegal(String check, String dest){
        Pattern regex = Pattern.compile(check);
        Matcher matcher = regex.matcher(dest);
        return matcher.matches();
    }

    public static void main(String[] args) {
        String[] emails = {
        "cynthia_017@163.com",
        "150939468@qq.com",
        "miikii2008@gmail.com",
        "shilibleach@yahoo.cn",
        "503609793@qq.com",
        "mijaewbv@kmvyhaxe.com",
        "syvia_lili@163.com",
        "313654879@qq.com",
        "mijobs@126.com",
        "mai961@qq.com",
        "esas@yeah.net",
        "mike@toncom.cn"
        };
//        for(String email : emails)
//           logger.info(isLegalEmail(email) + "");
        String[] tels = {"16692613503",
                        "13271091097",
                        "17596232565",
                        "16692637923",
                        "18539880273",
                        "15672802031",
                        "16650728272",
                        "15539047631",
                        "13037558712",
                        "15660889105",
                        "17638017238",
                        "15617027161",
                        "17550577913",
                        "18539889565",
                        "15638630875",
                        "15518617063",
                        "13103906953",
                        "16650715501"};
        for(String tel : tels)
            logger.info(isLegalTel(tel)+"");
    }
}
